import { AppModel } from '../../../../models/app.js'
const ModelApp = new AppModel()
const App = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    activity: Object,
    type: Number
  },

  /**
   * 组件的初始数据
   */
  data: {
    bindPhoneVisible: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //预约专场
    trailerActivity() {
      //判断是否绑定手机号
      const self = this
      const userInfo = App.globalData.userInfo
      if (!userInfo.userPhone || userInfo.userPhone == 0) {
        this.triggerEvent('subscribe')
      } else {
        //已绑定手机号
        const params = {
          specialId: this.data.activity.id
        }
        ModelApp.selectAppointment(params)
          .then(res => {
            this.data.activity.specialStatus = 1
            self.setData({
              activity: self.data.activity
            })
            App.WxService.showToast({
              title: '预约成功',
              icon: 'none'
            })
          })
          .catch()
      }
    },
    // 去专场详情
    goActivity() {
      const specialCode = this.data.activity.specialCode
      wx.navigateTo({
        url: `/pages/activity/index?scode=${specialCode}`
      })
    },
    //去专场预览
    goTrailer() {
      const activity = this.data.activity
      // 如果预告已经开启
      if (activity.specialOpen) {
        wx.navigateTo({
          url: `/pages/trailer/index?scode=${activity.specialCode}`
        })
      }
    },
    // 分享
    doShare() {
      this.triggerEvent('share', {
        activity: this.data.activity,
        type: this.data.type
      })
    }
  }
})
